package com.ylbh.common.utils;

import com.alibaba.fastjson.JSON;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.ylbh.modules.shortmessage.entity.AppSmsTemplate;
import com.ylbh.common.pojo.shortmessage.vo.SmsTemplateVO;
import io.swagger.annotations.Api;

/**
 * @author: wjc
 * @date: 2019/10/14 11:07
 */
@Api("阿里云短信模板添加")
public class AddSmsTemplate {

    public static SmsTemplateVO AddTemplate(AppSmsTemplate appSmsTemplate){
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou",SmsUtils.accessKeyId,SmsUtils.accessKeySecret);
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        request.setMethod(MethodType.POST);
        request.setDomain(SmsUtils.domain);
        request.setVersion("2017-05-25");
        request.setAction("AddSmsTemplate");
        request.putQueryParameter("RegionId","cn-hangzhou");
        request.putQueryParameter("TemplateType","2");
        request.putQueryParameter("TemplateName", appSmsTemplate.getName());
        request.putQueryParameter("TemplateContent", appSmsTemplate.getContent());
        request.putQueryParameter("Remark", appSmsTemplate.getRemarks());
        CommonResponse response = new CommonResponse();
        try {
            response = client.getCommonResponse(request);
        } catch (ClientException e) {
            e.printStackTrace();
        }
        return JSON.parseObject(response.getData(), SmsTemplateVO.class);
    }
    public static void main(String[] args) {
        AppSmsTemplate appSmsTemplate = new AppSmsTemplate();
        appSmsTemplate.setContent("8888");
        appSmsTemplate.setName("88888");
        appSmsTemplate.setRemarks("88888");
        SmsTemplateVO str = AddTemplate(appSmsTemplate);
        System.out.println(str.toString());
    }
}
